package fr.afcepf.atod18.commande.jms;

import java.util.Date;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

import fr.afcepf.atod18.commande.entity.EtatCommande;

@Service
public class JmsProducer {

    private JmsTemplate jmsTemplate;

    public void envoyerMessage(final int idCommande,
            final EtatCommande etatCommande) {

        jmsTemplate.send(new MessageCreator() {
            public Message createMessage(final Session session)
                    throws JMSException {
                return session.createTextMessage("Commande " + idCommande + " "
                        + etatCommande.getId() + " <" + etatCommande.getLibelle() + "> " + new Date());
            }
        });
    }

    public JmsTemplate getJmsTemplate() {
        return jmsTemplate;
    }

    public void setJmsTemplate(final JmsTemplate jmsTemplate) {
        this.jmsTemplate = jmsTemplate;
    }
}